<template>
  <div>
    <div id="top">考试得分</div>
<van-count-down :time="time" format="mm:ss" />
    <div id="TID">

      <div id="TID_a">
      <span id="T_a">单选题 </span>
      <span id="T_b">得分：<span>{{ truefen }}</span></span>
      <button @click="e2('测试未结束确定提前提交吗')" id="Bjiao">交卷</button>
      <button @click="c" id='but'>下一题</button>
      <span id='Span'>
        <span id='Span_a'>{{ index }}</span>
        <span>/{{CEsum}}</span>
      </span>
   
      </div>
    </div>
    <div id="timu">
      <div id="title">
        <p>{{ timucopy.title }}</p>
      </div>
      <div
        id="A"
        :class="[xuan, { noxuanxiang: noA }, { yesxuanxiang: yesA }]"
        @click="d('A')"
      >
        <P>A {{ timucopy.A }}</P>
      </div>
      <div
        id="B"
        :class="[xuan, { noxuanxiang: noB }, { yesxuanxiang: yesB }]"
        @click="d('B')"
      >
        <P>B {{ timucopy.B }}</P>
      </div>
      <div
        id="C"
        :class="[xuan, { noxuanxiang: noC }, { yesxuanxiang: yesC }]"
        @click="d('C')"
      >
        <P>C {{ timucopy.C }}</P>
      </div>
      <div
        id="D"
        :class="[xuan, { noxuanxiang: noD }, { yesxuanxiang: yesD }]"
        @click="d('D')"
      >
        <P>D {{ timucopy.D }}</P>
      </div>
    </div>


  <div id='jianjie' v-if="kaiguan">

   <div id="jianjie_a">
      <p class="ttt">正确答案:</p>
      <p id='TT'>{{TT}}</p>
   </div>

   <div id="jianjie_b">
       <p class="ttt">您选择的答案:</p>
      <p id='FF'>{{FF}}</p>
   </div>
  </div>

  <div id='daan' v-if="kaiguan">
  <p>参考解析:</p>

  <div>暂无解析</div>
  </div>

  </div>
</template>

<script>
import axios from "axios";
import { Dialog } from 'vant'

export default {
  data() {
    return {
time: 2*60 * 1000,

      xuan: "xuanxiang", //最初样式
      timu: [], //数据库题目
      timucopy: [], //随机数取出的数据库数
      index: 1,
      //控制正确答案样式yesxuanxiang
      yesA: false,
      yesB: false,
      yesC: false,
      yesD: false,

      //控制错误答案样式noxuanxiang
      noA: false,
      noB: false,
      noC: false,
      noD: false,

      //控制每道题点击只能为一次
      yici: 0,
      //得分情况
      truefen: 0,
    //控制解析的开关
      kaiguan:false,

    //控制测试总数
    CEsum:20,

    //控制随机数
    CEsuiji:11,
      
      TT:'C',
      FF:'B',


      DDDD:''

    };
  },

  created() {
    this.a();
     this.setTimer()
  },

  methods: {
    a() {
      var _that = this;
      axios
        .get("/api/vue_title")
        .then((res) => {
          console.log(res.data.message);
          _that.timu = res.data.message;

          // let shu = Math.round(Math.random() * this.CEsuiji);
          // this.timucopy = this.timu[shu];
        this.b();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    b() {
      let shu = Math.round(Math.random() * this.CEsuiji);
      this.timucopy = this.timu[shu];
    },
    c() {
      this.kaiguan=false
      this.yici = 0;
     
        (this.yesA = false),
        (this.yesB = false),
        (this.yesC = false),
        (this.yesD = false),
        (this.noA = false),
        (this.noB = false),
        (this.noC = false),
        (this.noD = false);

      if (this.index < this.CEsum) {
        this.b();
        this.index++;
      } else {
        this.e2('这已经是最后一道题了是否提交');
        this.d(this.DDD);
      }
    },
    d(msg) {
      if (this.yici == 0) {
      this.kaiguan=true
      this.FF=msg
      this.TT=this.timucopy.truetitle
        if (msg == "A") {
            (this.noA = true),
            (this.noB = false),
            (this.noC = false),
            (this.noD = false);
        }
        if (msg == "B") {
            (this.noB = true),
            (this.noA = false),
            (this.noC = false),
            (this.noD = false);
        }
        if (msg == "C") {
            (this.noC = true),
            (this.noB = false),
            (this.noA = false),
            (this.noD = false);
        }
        if (msg == "D") {
          (this.noD = true),
            (this.noB = false),
            (this.noC = false),
            (this.noA = false);
        }

        if (this.timucopy.truetitle == "A") {
          (this.yesA = true),
            (this.yesB = false),
            (this.yesC = false),
            (this.yesD = false);
        }

        if (this.timucopy.truetitle == "B") {
          (this.yesB = true),
            (this.yesA = false),
            (this.yesC = false),
            (this.yesD = false);
        }

        if (this.timucopy.truetitle == "C") {
          (this.yesC = true),
            (this.yesB = false),
            (this.yesA = false),
            (this.yesD = false);
        }
        if (this.timucopy.truetitle == "D") {
          (this.yesD = true),
            (this.yesB = false),
            (this.yesC = false),
            (this.yesA = false);
        }
     
        if (msg == this.timucopy.truetitle) {
          this.truefen++;
        }
        this.yici = 1;
        this.DDD=msg
      }
    },
    e() {

        let id=localStorage.getItem("id");
        let fen = localStorage.getItem("fen");
        let tm=this.truefen+parseInt(localStorage.getItem("fenSum"))
 
         axios
          .get("/api/vue_admZong?tm="+tm+'&id='+id)
          .then((res) => {   
            history.go(0) 
            localStorage.setItem('fenSum',tm)
          })
          .catch((err) => {});
        
        console.log(this.truefen);
        console.log(fen);
      if (this.truefen > fen) {
        alert('恭喜你打破原来记录')
        axios
          .get("/api/vue_admUpdata?fen="+this.truefen+'&id='+id)
          .then((res) => {
             history.go(0) 
            localStorage.setItem('fen',this.truefen)
            console.log(res);
          })
          .catch((err) => {});
      }

       this.$router.push("/home");
    },
    setTimer() {
              
                  setInterval( () => {
                       this.e()
                    }, 120000)
                
            },

    e2(msg){
  Dialog.confirm({
   message:msg ,
})
  .then(() => {
     this.e();
  })
  .catch(() => {
    // on cancel
  });

    }

  },
};
</script>


<style scoped>

.van-count-down{

   font-size: 28px;
    position: absolute;
    right: 46%;
    top: 10%;
}


#Bjiao{

  background-color: rgb(14, 215, 148);
  color: aliceblue;
  border-radius: 10px;
  border:none;
  margin-left: 40px;
  width: 70px;
  font-size: 20px;
}

#T_a{
  font-size: 25px;
  line-height: 100px;
  color: rgb(69, 142, 252);
}

#T_b{
  font-size: 20px;
  margin: 0 auto;
}

#T_b span{
   color: rgb(137, 246, 54);
   font-size: 25px;
}
#Span_a{
  font-size: 30px;
  color: rgb(4, 253, 74);
}

#but{
  background-color: rgb(6, 131, 247);
  color: aliceblue;
  border: none;
  height: 30px;
  border-radius: 10px;
  float: right;
  margin-top:35px;
  margin-right: 10px;
  margin-left: 10px;
}
#Span{
  float: right;
  font-size: 20px;
   line-height: 100px;
}

#TID {
  height: 70px;
  width: 90%;
  background-color: rgb(252, 252, 252);
  margin: 0 auto;
  margin-top: 30px;
  border-radius: 5px;
}
#top {
  text-align: center;
  font-size: 20px;
  line-height: 60px;
  width: 100%;
  height: 55px;
  background-color: rgb(252, 252, 252);
  border-radius: 5px;
}

#timu {
  width: 90%;
  height: 630px;
  background-color: rgb(252, 252, 252);
  margin: 0 auto;
  margin-top: 2px;
  border-radius: 5px;
  padding-top: 10px;
}

.xuanxiang {
  height: 80px;
  width: 90%;
  margin: 0 auto;
  margin-top: 20px;
  border: 1px solid rgb(187, 183, 183);
  display: flex;
  justify-content: center;
  flex-direction: column;
}

.noxuanxiang {
  height: 80px;
  width: 90%;
  margin: 0 auto;
  margin-top: 20px;
  border: 1px solid rgb(247, 98, 12);
  background-color: rgba(247, 98, 12, 0.1);
  color: rgb(247, 98, 12);
  display: flex;
  justify-content: center;
  flex-direction: column;
}
.yesxuanxiang {
  height: 80px;
  width: 90%;
  margin: 0 auto;
  margin-top: 20px;
  border: 1px solid rgb(56, 224, 27);
  background-color: rgba(56, 224, 27, 0.1);
  color: rgb(56, 224, 27);
  display: flex;
  justify-content: center;
  flex-direction: column;
}

#title {
  width: 95%;
  margin: 0 auto;
  height: 180px;
  font-size: 15px;
  /* border: 1px solid rgb(187, 183, 183); */
  padding: 5px;
}
.xuanxiang p {
  font-size: 25px;
  margin-left: 10px;
}

.yesxuanxiang p {
  font-size: 25px;
  margin-left: 10px;
}

#title p {
  font-size: 20px;
}

#jianjie{

  width: 90%;
  height: 70px;
  background-color: rgb(252, 252, 252);
  margin: 0 auto;
  margin-top: 10px;
  display: flex;
  
}
  #jianjie_a{
    width: 49%;
    height: 70px;
    border-right: 1px solid rgb(175, 171, 171);
    line-height: 10px;

  }

  #jianjie_b{
     float: right;
     width: 49%;
     height: 70px;
     line-height: 10px;
  }
#daan{
  width: 90%;
  height: 70px;
  background-color: rgb(252, 252, 252);
  margin: 0 auto;
  border-top: 1px solid rgb(175, 171, 171);
}

#daan p{
      color: rgb(189, 183, 183);
      width: auto;
      margin-left: 10px;
       line-height: 10px;

}

#TT{

  font-size: 25px;
  color: rgb(64, 248, 186);
  text-align: center;
}

#FF{
  font-size: 25px;
  color: rgb(78, 100, 243);
  text-align: center;
}

.ttt{
  color: rgb(189, 183, 183);
  text-align: center;
}
</style>

